/*
 * @Author: funlee
 * @Email: i@funlee.cn
 * @Date: 2018-05-05 21:36:55
 * @Description: 实现一个单例模式
 */
const log = console.log.bind();
log('---单例模式---');

/**
 * 创建一个单例模式
 * @param {String} name 
 */
var Singleton = function (name) {
  this.name = name;
  this.instance = null;
}

Singleton.prototype.getName = function () {
  log(this.name)
}
// 通过 getInstance 来创建对象实例
Singleton.getInstance = function (name) {
  if (!this.instance) {
    this.instance = new Singleton(name)
  }
  return this.instance;
}

var a = Singleton.getInstance('sven1');
var b = Singleton.getInstance('sven2');

a.getName()
b.getName()

log(a === b)







